import ejs from 'ejs'
import { defaultTemplate } from './template/default'
import { hydraTemplate } from './template/hydra'
import { reactTemplate } from './template/react'
import { pugTemplate } from './template/pug'
let temp = {
  hydra: hydraTemplate,
  eboss: defaultTemplate,
  react: reactTemplate
}
export function temgen(codeOpts = {}, opts = {}) {
  let code = codeOpts.code || ''
  let data = codeOpts.data || []
  let events = codeOpts.events || []
  console.log('temgen', data, events)
  // 构建模板
  let template = ''
  if (opts.templateName) {
    // console.log(opts.templateName)
    if (opts.templateType === 'pug') {
      // TODO 后续优化逻辑
      template = pugTemplate
    } else {
      template = temp[opts.templateName.value]
    }
  } else {
    template = defaultTemplate
  }
  if (opts.templateName.value === 'react') {
    let result = ejs.render(template, {
      className: 'demo',
      code: code,
      state: data,
      events: events
    })
    return result
  }
  if (opts.templateName.value === 'eboss') {
    let result = ejs.render(template, {
      code: code,
      data: data,
      events: events
    })
    return result
  }
  return ''
}


